package com.ruoyi.web.controller.pj;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.domain.PjOrders;
import com.ruoyi.web.service.IPjOrdersService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 订单管理Controller
 *
 * @author mike
 * @date 2024-12-21
 */
@RestController
@RequestMapping("/pj/orders")
public class PjOrdersController extends BaseController
{
    @Autowired
    private IPjOrdersService pjOrdersService;

    /**
     * 查询订单管理列表
     */
    @PreAuthorize("@ss.hasPermi('pj:orders:list')")
    @GetMapping("/list")
    public TableDataInfo list(PjOrders pjOrders)
    {
        startPage();
        List<PjOrders> list = pjOrdersService.selectPjOrdersList(pjOrders);
        return getDataTable(list);
    }

    /**
     * 导出订单管理列表
     */
    @PreAuthorize("@ss.hasPermi('pj:orders:export')")
    @Log(title = "订单管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PjOrders pjOrders)
    {
        List<PjOrders> list = pjOrdersService.selectPjOrdersList(pjOrders);
        ExcelUtil<PjOrders> util = new ExcelUtil<PjOrders>(PjOrders.class);
        util.exportExcel(response, list, "订单管理数据");
    }

    /**
     * 获取订单管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('pj:orders:query')")
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") Long orderId)
    {
        return success(pjOrdersService.selectPjOrdersByOrderId(orderId));
    }

    /**
     * 新增订单管理
     */
    @PreAuthorize("@ss.hasPermi('pj:orders:add')")
    @Log(title = "订单管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PjOrders pjOrders)
    {
        return toAjax(pjOrdersService.insertPjOrders(pjOrders));
    }

    /**
     * 修改订单管理
     */
    @PreAuthorize("@ss.hasPermi('pj:orders:edit')")
    @Log(title = "订单管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PjOrders pjOrders)
    {
        return toAjax(pjOrdersService.updatePjOrders(pjOrders));
    }

    /**
     * 删除订单管理
     */
    @PreAuthorize("@ss.hasPermi('pj:orders:remove')")
    @Log(title = "订单管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderIds}")
    public AjaxResult remove(@PathVariable Long[] orderIds)
    {
        return toAjax(pjOrdersService.deletePjOrdersByOrderIds(orderIds));
    }
}
